package ca.nfb.media.nfbPlayer.ui
{
	import ca.nfb.media.nfbPlayer.ComModule;
	import ca.nfb.media.nfbPlayer.views.NFBPlayerView;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.StageDisplayState;
	import flash.text.TextField;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.TimerEvent;
	import flash.geom.Point;
	import flash.net.URLRequest;
	import flash.net.navigateToURL;
	import flash.ui.Mouse;
	import flash.utils.Timer;

	public class PlaylistRollOver extends NFBPlayerView
	{
		
		public static var rollOverDelay				:Number = 450;	
		public var image							:NFBImage 	= new NFBImage(204, 114);
		private var _data							:Object = new Object();
		private var elementData						:Object;
		
		private var localWidth						:Number = 204;
		private var localHeight						:Number = 114;
		
		private var targettedDisplayObject			:DisplayObject;
		private var timer							:Timer = new Timer(PlaylistRollOver.rollOverDelay, 1);
		public var showing							:Boolean = false;
		
		public function PlaylistRollOver()
		{
			super();	
			this.visible = false;
				
			timer.addEventListener(TimerEvent.TIMER_COMPLETE, displayRollOver, false, 0, true);
			title_txt.mouseEnabled = false;
			desc_txt.mouseEnabled = false;
			this.useHandCursor = true;
			this.buttonMode = true;
			this.mouseChildren = false;
			this.addEventListener(MouseEvent.MOUSE_OUT, mOut, false, 0, true);
			this.addEventListener(MouseEvent.CLICK, clicked, false, 0, true);
			image.maintainAspectRatio = true;
			image.addEventListener(NFBImage.IMAGE_LOADED, imageLoaded, false, 0, true);
			image.addEventListener(NFBImage.IMAGE_LOADING, imageLoading, false, 0, true);
			
			MovieClip(imageHolder_mc).addChild(image);
		}
		
		private function imageLoaded(evt:Event):void
		{
			image.alpha = .15;

		}
		
		private function imageLoading(evt:Event):void
		{
			
		}
		
		private function mOut(evt:MouseEvent):void
		{
			this.hide();
		}
		
		private function clicked(evt:MouseEvent):void
		{
			
		/* 	
			CLICKED 
			ComModule.getInstance().core.player.stop();
			ComModule.getInstance().core.showPreviewImage = false;
			ComModule.getInstance().core.showWarningMessages = false;
			
			ComModule.getInstance().core.setCurrentState(NFBPlayer.DEFAULT_STATE);	 */
			
		}
			
		
		public function show(dataItem:Object, targetDisplayObject:DisplayObject=null):void
		{
			this.visible = false;
			elementData = dataItem;
				
			// image.startLoading(yourIMAGEURL);
			
			var localPt:Point = new Point(targetDisplayObject.x, targetDisplayObject.y);
			stage.localToGlobal(localPt);
			
			if (stage.displayState != StageDisplayState.FULL_SCREEN)
			{
				if (localPt.x+localWidth < stage.stageWidth)
				{
					this.x = localPt.x
				}
				else
				{
					this.x = localPt.x + (targetDisplayObject.width - localWidth);
				}
			
				this.y = localPt.y;
			}
			else
			{
				this.x = localPt.x + (stage.stageWidth-core.finalPlaylistView.width) / 2;
				this.y = localPt.y+((stage.stageHeight-core.controllerHeight) - core.finalPlaylistView.height) / 2;	
			}
				
			title_txt.htmlText = elementData.title;
			desc_txt.htmlText = elementData.director;
		
			if (TextField(title_txt).numLines <= 1)
			{
				desc_txt.y = 27;
				desc_txt.height = 80;
			}
			else
			{
				desc_txt.y = 51;
				desc_txt.height = 60;
			}
			
			if (timer.running)
				timer.stop();
				
			timer.start();		
			
		}	
		
		public function hide():void
		{
			this.visible = false;
			if (timer.running)
				timer.stop();
				
			showing = false;	
		}
		
		public function displayRollOver(evt:TimerEvent):void
		{
			if (timer.running)
				timer.stop();
				
			showing = true;
			this.visible = true;
			
		}
		
		override public function close(evt:*=null):void
		{
			
		}	
	}
}